package com.dems.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dems.admin.security.SecurityUtils;
import com.dems.dao.dataobject.RoomUserRelation;
import com.dems.domain.JsonResponse;
import com.dems.domain.RoomUserRelationReqVO;
import com.dems.service.RoomUserRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/roomUserRelation")
public class RoomUserRelationController {
    @Autowired
    private RoomUserRelationService roomUserRelationService;

    @PostMapping("/find")
    public JsonResponse<Page<RoomUserRelation>> find(@RequestBody RoomUserRelationReqVO reqVO){
        return JsonResponse.success(roomUserRelationService.findByPage(reqVO));
    }

    @PostMapping("/create")
    public JsonResponse create(@RequestBody List<RoomUserRelation> relation){
        return JsonResponse.success(roomUserRelationService.saveRelation(relation, SecurityUtils.getLoanassistUser()));
    }

    @PostMapping("/update")
    public JsonResponse update(@RequestBody RoomUserRelation relation){
        return JsonResponse.success(roomUserRelationService.updateRelation(relation, SecurityUtils.getLoanassistUser()));
    }
}
